﻿using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using DynCMS.NET.Core.Entities;
using DynCMS.NET.Core.Interfaces;
using DynCMS.NET.DataAccess.Mappings;

namespace DynCMS.NET.DataAccess.Implementation
{
    public class DataContext : DbContext
    {
        /// <summary>
        /// Initializes the <see cref="WCContext"/> class.
        /// </summary>
        static DataContext()
        {
            Database.SetInitializer<DataContext>(new CreateDatabaseIfNotExists<DataContext>());
        }

        /// <summary>
        /// Gets or sets the instance id.
        /// </summary>
        /// <value>The instance id.</value>
        public Guid InstanceId
        {
            get;
            private set;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:WCContext"/> class.
        /// </summary>
        public DataContext(string dbName = "DynCMS.NET")
            : base(dbName)
        {
            this.InstanceId = Guid.NewGuid();
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
            //modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.ColumnAttributeConvention>();
            modelBuilder.Configurations.Add(new PageMap());
        }

        /// <summary>
        /// Gets or sets the pages.
        /// </summary>
        /// <value>The pages.</value>
        public DbSet<Page> Pages
        {
            get;
            set;
        }
    }
}